namespace CSharpPro._1013;
using System;
using System.Collections.Generic;
public class Demo

{
    // 作业一
    public static int[] SortThreeNumbers(int x, int y, int z)
    {
        int[] numbers = { x, y, z };
        Array.Sort(numbers);
        return numbers;
    }
    
    //作业二
    public static List<int> GetValidNumbers()
    {
        List<int> result = new List<int>();
        
        for (int i = 1; i <= 100; i++)
        {
            if (IsValidNumber(i))
            {
                result.Add(i);
            }
        }
        return result;
    }
    public static int CalculateSum(List<int> numbers)
    {
        int sum = 0;
        foreach (int num in numbers)
        {
            sum += num;
        }
        return sum;
    } 
    private static bool IsValidNumber(int number)
    {
        if (number % 7 == 0)
        {
            return false;
        }
        int temp = number;
        while (temp > 0)
        {
            if (temp % 10 == 7)
            {
                return false;
            }
            temp /= 10;
        }
        return true;
    }
    
    //作业三
    public void PrintMultiplicationTable()
    {
        Console.WriteLine("九九乘法表：");
        Console.WriteLine("==================================");
        for (int i = 1; i <= 9; i++)
        {
            for (int j = 1; j <= i; j++)
            {
                Console.Write($"{j} × {i} = {i * j}\t");
            }
            Console.WriteLine();
        }
        Console.WriteLine("==================================");
    }

    //作业四
    public static List<int> GetFactors(int number)
    {
        List<int> factors = new List<int>();
        for (int i = 1; i <= number / 2; i++)
        {
            if (number % i == 0)
            {
                factors.Add(i);
            }
        }
        return factors;
    }
    public static bool IsPerfectNumber(int number)
    {
        if (number <= 1) return false;
        List<int> factors = GetFactors(number);
        int sum = 0;
        foreach (int factor in factors)
        {
            sum += factor;
        }
        return sum == number;
    }
    public static List<int> FindPerfectNumbers(int maxNumber)
    {
        List<int> perfectNumbers = new List<int>();
        for (int i = 2; i <= maxNumber; i++)
        {
            if (IsPerfectNumber(i))
            {
                perfectNumbers.Add(i);
            }
        }
        return perfectNumbers;
    }
    
    //作业五
    public static int GetDigitCount(int number)
    {
        return number.ToString().Length;
    }
    public static void PrintDigitsReverse(int number)
    {
        string numStr = number.ToString();
        for (int i = numStr.Length - 1; i >= 0; i--)
        {
            Console.Write(numStr[i] + " ");
        }
        Console.WriteLine();
    }
    //作业六
    public static void PrintDiamond(int totalRows)
    {
        int half = totalRows / 2;
        for (int i = 0; i <= half; i++)
        {
            for (int j = 0; j < half - i; j++)
            {
                Console.Write(" ");
            }
            for (int j = 0; j < 2 * i + 1; j++)
            {
                Console.Write("*");
            }
            Console.WriteLine();
        }
        for (int i = half - 1; i >= 0; i--)
        {
            for (int j = 0; j < half - i; j++)
            {
                Console.Write(" ");
            }
            for (int j = 0; j < 2 * i + 1; j++)
            {
                Console.Write("*");
            }
            Console.WriteLine();
        }
    }
}
